/*
	该程序仅在测试阶段使用，用于控制PL端的使能信号:GPIO_DDR_WR_EN
*/

#include "SchmidtCAM.h"

int main( int argc, char *argv[] ){

	if( argc != 2 ){
		printf("usage:\n");
		printf("\t%s opt\n", argv[0]);
		printf("\topt could be 0 or 1.\n");
		return 0;
	}

	int fd = open("/dev/mem", O_RDWR | O_SYNC);
	uint *ptr1 = mmap(NULL, 10, PROT_READ | PROT_WRITE, MAP_SHARED, fd, ADDR_GPIO_OUT);
	uint *gpio_reg 		= ptr1;		// 0x41200000
	// uint *gpio2_reg		= ptr1+2;	// 0x41200008

	int opt = atoi(argv[1]);

	if( opt == 1 ){
		// set BIT_DDR_WR_EN to 0
		clrbit(*gpio_reg, BIT_DDR_WR_EN);
	} else if( opt == 0 ){
		// set BIT_DDR_WR_EN to 1
		setbit(*gpio_reg, BIT_DDR_WR_EN);
	} else {
		printf("wrong opt: %d\n", opt);
		printf("exit now!\n");
		exit(0);
	}

	munmap(ptr1,10);
	close(fd);

	return 0;
}

